/**
 * jaroverlay-maven-plugin : add remove replace content and repackage nested archives
 * 
 * Copyright (C) 2008  Paul Merlin
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.n0pe.jaroverlay.model;


import java.io.File;
import java.util.LinkedList;
import java.util.List;


/**
 * @author Paul Merlin <eskatos@n0pe.org>
 */
public class Archive {


    private Archive parent;


    private List children = new LinkedList();


    private File packedSourceFile;


    private File unpackedDirectory;


    private File repackedFile;


    private Integer deep = new Integer(0);


    public static Archive create(Archive parent, File packedSourceFile, File unpackedDirectory, Integer deep) {
        Archive a = create(parent, packedSourceFile, unpackedDirectory);
        a.deep = deep;
        return a;
    }


    public static Archive create(Archive parent, File packedSourceFile, File unpackedDirectory) {
        final Archive a = new Archive();
        a.parent = parent;
        a.packedSourceFile = packedSourceFile;
        a.unpackedDirectory = unpackedDirectory;
        if (a.parent != null) {
            a.parent.children.add(a);
        }
        return a;
    }


    public List getChildren() {
        return children;
    }


    public File getPackedSourceFile() {
        return packedSourceFile;
    }


    public Archive getParent() {
        return parent;
    }


    public File getUnpackedDirectory() {
        return unpackedDirectory;
    }


    public File getRepackedFile() {
        return repackedFile;
    }


    public void setRepackedFile(File repackedFile) {
        this.repackedFile = repackedFile;
    }


    public Integer getDeep() {
        return deep;
    }


    public String toString() {
        return unpackedDirectory.getAbsolutePath();
    }


    public boolean equals(Object obj) {
        if (!(obj instanceof Archive)) {
            return false;
        }
        return unpackedDirectory.getAbsolutePath().equals(((Archive) obj).unpackedDirectory.getAbsolutePath());
    }


    public int hashCode() {
        return 37 + unpackedDirectory.hashCode();
    }


}
